<?php

namespace app\admin\controller;

use app\helpers\Common;

use think\Request;

class ArticleCate extends Base
{
    public function initialize()
    {
        parent::initialize();

        $this->defaultWhere = [
            ['status', '<>', config('constants.SOFT_DELETE_STATUS')]
        ];
        $this->defaultOrder = 'created_at DESC';
    }

    /**
     * 筛选条件
     */
    public function getFilterWhere($request)
    {
        $param = $request->param();
        $where = [];
        if (isset($param['name']) && $param['name']) {
            $where[] = ['name', 'like', '%' . trim($param['name']) . '%'];
        }
        if (isset($param['range_date']) && $param['range_date']) {
            $rangeDate = explode(' ~ ', $param['range_date']);
            $where[] = ['created_at', '>=', strtolower($rangeDate[0])];
            $where[] = ['created_at', '<=', strtotime($rangeDate[1])];
        }

        return $where;
    }
}